home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / nos042_s / global.h < prev    next >
C/C++ Source or Header  |  1994-09-16  |  9KB  |  312 lines

  1. /****************************************************************************
  2. *    $Id: global.h 1.6 93/07/16 11:44:56 ROOT_DOS Exp $
  3. *    24 Aug 92    1.3        GT    Redefine time.
  4. *    13 Sep 92    1.4        GT    New file modes.
  5. *    09 May 93    1.6        GT    Fix warnings.    
  6. *
  7. *  ATARI Version by David Nash - dnash@chaos.demon.co.uk
  8. *
  9. *  stdio.h and stdlib included
  10. *  shadow definitions added for fileops
  11. *
  12. *    28.08.94 DFN - define rflush, potl & ltop as macros
  13. ****************************************************************************/
  14.  
  15. #ifndef _GLOBAL_H
  16. #define    _GLOBAL_H
  17.  
  18. /* Global definitions used by every source file.
  19.  * Some may be compiler dependent.
  20.  */
  21.  
  22. #ifdef ATARI
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <errno.h>
  26. #endif
  27.  
  28. /*
  29.     Include config.h so that definitions are propagated.
  30.     eg. FILTER is needed in iface.h
  31. */
  32.  
  33. #include "config.h"
  34.  
  35. #if    defined(__TURBOC__) || defined(__STDC__) || defined(LATTICE)
  36. #define    ANSIPROTO    1
  37. #endif
  38.  
  39. #ifndef    __ARGS
  40. #ifdef    ANSIPROTO
  41. #define    __ARGS(x)    x
  42. #else
  43. #define    __ARGS(x)    ()
  44. #endif
  45. #endif
  46.  
  47.  
  48. #if    !defined(AMIGA) && (defined(LATTICE) || defined(MAC) || defined(__TURBOC__))
  49. /* These compilers require special open modes when reading binary files.
  50.  *
  51.  * "The single most brilliant design decision in all of UNIX was the
  52.  * choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
  53.  *
  54.  * "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
  55.  * should be shot!" -- P. Karn's corollary to O'Dells' declaration
  56.  */
  57. #define    READ_BINARY        "rb"
  58. #define    WRITE_BINARY    "wb"
  59. #define    APPEND_BINARY    "ab+"
  60. #define    READ_TEXT        "rt"
  61. #define    WRITE_TEXT        "wt"
  62. #define    APPEND_TEXT        "at+"
  63. #define    RW_LOOKUP_TEXT    "rt+"
  64. #define    RW_CREATE_TEXT    "wt+"
  65.  
  66. #else
  67.  
  68. #define    READ_BINARY        "r"
  69. #define    WRITE_BINARY    "w"
  70. #define    APPEND_BINARY    "a+"
  71. #define    READ_TEXT        "r"
  72. #define    WRITE_TEXT        "w"
  73. #define    APPEND_TEXT        "a+"
  74. #define    RW_LOOKUP_TEXT    "r+"
  75. #define    RW_CREATE_TEXT    "w+"
  76.  
  77. #endif
  78.  
  79. /* These two lines assume that your compiler's longs are 32 bits and
  80.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  81.  * but it doesn't matter if they're signed or unsigned.
  82.  */
  83. typedef long int32;                                /* 32-bit signed integer     */
  84. typedef unsigned short int16;                    /* 16-bit unsigned integer */
  85. typedef unsigned char byte_t;                    /*  8-bit unsigned integer */
  86. #define    uchar(x) ((unsigned char)(x))
  87. #define    MAXINT16 65535L                        /* Largest 16-bit integer     */
  88. #define    MAXINT32 4294967295L                    /* Largest 32-bit integer     */
  89.  
  90. #define    HASHMOD    7        /* Modulus used by hash_ip() function */
  91.  
  92. /* The "interrupt" keyword is non-standard, so make it configurable */
  93. #if    defined(__TURBOC__) && defined(MSDOS)
  94. #define    INTERRUPT    void interrupt
  95. #else
  96. #define    INTERRUPT    void
  97. #endif
  98.  
  99. /* Note that these definitions are on by default if none of the Turbo-C style
  100.  * memory model definitions are on; this avoids having to change them when
  101.  * porting to 68K environments.
  102.  */
  103. #if    !defined(__TINY__) && !defined(__SMALL__) && !defined(__MEDIUM__)
  104. #define    LARGEDATA    1
  105. #endif
  106.  
  107. #if    !defined(__TINY__) && !defined(__SMALL__) && !defined(__COMPACT__)
  108. #define    LARGECODE    1
  109. #endif
  110.  
  111. /* Since not all compilers support structure assignment, the ASSIGN()
  112.  * macro is used. This controls how it's actually implemented.
  113.  */
  114. #ifdef    NOSTRUCTASSIGN    /* Version for old compilers that don't support it */
  115. #define    ASSIGN(a,b)    memcpy((char *)&(a),(char *)&(b),sizeof(b));
  116. #else            /* Version for compilers that do */
  117. #define    ASSIGN(a,b)    ((a) = (b))
  118. #endif
  119.  
  120. /* Define null object pointer in case stdio.h isn't included */
  121. #ifndef    NULL
  122. /* General purpose NULL pointer */
  123. #define    NULL (void *)0
  124. #endif
  125. #define    NULLCHAR (char *)0    /* Null character pointer */
  126. #define    NULLCHARP (char **)0    /* Null character pointer pointer */
  127. #define    NULLINT    (int *)0    /* Null integer pointer */
  128. #define    NULLFP     (int (*)())0    /* Null pointer to function returning int */
  129. #define    NULLVFP     (void (*)())0    /* Null pointer to function returning void */
  130. #define    NULLVIFP (INTERRUPT (*)())0
  131. #define    NULLFILE (FILE *)0    /* Null file pointer */
  132.  
  133. /* standard boolean constants */
  134. #define FALSE 0
  135. #define TRUE 1
  136. #define NO 0
  137. #define YES 1
  138.  
  139. /* string equality shorthand */
  140. #define STREQ(x,y) (strcmp(x,y) == 0)
  141.  
  142. /* Extract a short from a long */
  143. #define    hiword(x)    ((int16)((x) >> 16))
  144. #define    loword(x)    ((int16)(x))
  145.  
  146. /* Extract a byte from a short */
  147. #define    hibyte(x)    ((unsigned char)((x) >> 8))
  148. #define    lobyte(x)    ((unsigned char)(x))
  149.  
  150. /* Extract nibbles from a byte */
  151. #define    hinibble(x)    (((x) >> 4) & 0xf)
  152. #define    lonibble(x)    ((x) & 0xf)
  153.  
  154. /* Various low-level and miscellaneous functions */
  155. unsigned long availmem __ARGS((void));
  156. void *callocw __ARGS((unsigned nelem,unsigned size));
  157. int32 clock();
  158. int dirps __ARGS((void));
  159. #ifndef ATARI
  160. int getopt __ARGS((int argc,char *argv[],char *opts));
  161. #endif
  162. int htoi __ARGS((char *));
  163. long htol __ARGS((char *));
  164. char *inbuf __ARGS((int16 port,char *buf,int16 cnt));
  165. int16 hash_ip __ARGS((int32 addr));
  166. int istate __ARGS((void));
  167. void log __ARGS((int s,char *fmt, ...));
  168. int log2 __ARGS((int16 x));
  169. void *ltop __ARGS((long));
  170. void *mallocw __ARGS((unsigned nb));
  171. char *outbuf __ARGS((int16 port,char *buf,int16 cnt));
  172. long ptol __ARGS((void *));
  173. void restore __ARGS((int));
  174. void rflush __ARGS((void));
  175. void rip __ARGS((char *));
  176. char *smsg __ARGS((char *msgs[],unsigned nmsgs,unsigned n));
  177. int tprintf __ARGS((char *fmt,...));
  178. #if    !defined __TURBOC__
  179. char *strdup __ARGS((const char *));
  180. #endif
  181. int wildmat __ARGS((char *s,char *p,char **argv));
  182. #ifdef ANSI
  183. void ansi_putc __ARGS((struct screen *sp,char c));
  184. #endif
  185.  
  186. #include    <time.h>
  187.  
  188. time_t ka9q_time __ARGS((time_t *t));
  189.  
  190. #include <stdlib.h>
  191. #include <string.h>
  192.  
  193. #ifdef    AZTEC
  194. #define    rewind(fp)    fseek(fp,0L,0);
  195. #endif
  196.  
  197. #if    defined(__TURBOC__) && defined(MSDOS)
  198. #define movblock(so,ss,do,ds,c)    movedata(ss,so,ds,do,c)
  199. #ifndef outportw
  200. #define outportw outport
  201. #endif
  202. #ifndef inportw
  203. #define inportw inport
  204. #endif
  205.  
  206. #else
  207.  
  208. /* General purpose function macros already defined in turbo C */
  209. #ifndef    min
  210. #define    min(x,y)    ((x)<(y)?(x):(y))    /* Lesser of two args */
  211. #endif
  212. #ifndef max
  213. #define    max(x,y)    ((x)>(y)?(x):(y))    /* Greater of two args */
  214. #endif
  215. #ifdef    MSDOS
  216. #define MK_FP(seg,ofs)    ((void far *) \
  217.             (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  218. #endif
  219. #endif    /* __TURBOC __ */
  220.  
  221. #ifdef    AMIGA
  222. /* super kludge de WA3YMH */
  223. #ifndef    fileno
  224. #include <stdio.h>
  225. #endif
  226. #define fclose(fp)    amiga_fclose(fp)
  227. extern int amiga_fclose __ARGS((FILE *));
  228. extern FILE *tmpfile __ARGS((void));
  229.  
  230. extern char *sys_errlist[];
  231. extern int errno;
  232. #endif
  233.  
  234. /* Externals used by getopt */
  235. extern int optind;
  236. extern char *optarg;
  237.  
  238. /* Threshold setting on available memory */
  239. extern int32 Memthresh;
  240.  
  241. /* System clock - count of ticks since startup */
  242. extern int32 Clock;
  243.  
  244. /* Various useful standard error messages */
  245. extern char Badhost[];
  246. extern char Nospace[];
  247. extern char Notval[];
  248. extern char *Hostname;
  249. extern char Version[];
  250.  
  251. /* Your system's end-of-line convention */
  252. extern char Eol[];
  253.  
  254. /* connect () failure timeout value. */
  255.  
  256. extern int32 connect_wait_val;
  257.  
  258. extern void (*Gcollect[])();
  259.  
  260. #define    time    ka9q_time
  261.  
  262. #ifdef ATARI
  263.  
  264. /****************************************************************************
  265. *    shadow fopen() to fopenx() to translate seperators - DFN                 *
  266. ****************************************************************************/
  267.  
  268. #undef    fopen
  269. #define    fopen fopenx
  270. FILE *fopenx(const char *, const char *);
  271.  
  272. #undef    remove
  273. #define    remove    removex
  274. int    removex(const char *);
  275.  
  276. #undef    rename
  277. #define    rename renamex
  278. int    renamex(const char *, const char *);
  279.  
  280. #undef    open
  281. #define    open    openx
  282. int    openx(const char *, int, int);
  283.  
  284. #undef    creat
  285. #define     creat creatx
  286. int    creatx(const char *, int);
  287.  
  288. #undef    unlink
  289. #define    unlink unlinkx
  290. int    unlinkx(const char *);
  291.  
  292. #undef     access
  293. #define    access accessx
  294. int    accessx(const char *, int);
  295.  
  296. #undef     mkdir
  297. #define    mkdir mkdirx
  298. int    mkdirx(const char *);
  299.  
  300. /****************************************************************************
  301. *    Define some trivial functions as macros to save the function call             *
  302. ****************************************************************************/
  303.  
  304. #define    rflush()        fflush(stdout)                /* raw flush                        */
  305. #define    ptol(p)        (long)p                        /* pointer to long                */
  306. #define    ltop(l)        (void *)l                    /* long to pointer                */
  307.  
  308. #endif
  309.  
  310. #endif    /* _GLOBAL_H */
  311.